/**
 * LIOM Laboratory, Dec 21, 2012
 * Created by: flesage
 */
package ca.polymtl.liom.fileio;
import java.lang.String;
import java.util.Properties;
import java.io.*;

/**
 * @author flesage
 * This class creates and saves data to the info.txt file that is used to characterize
 * each experiment. It is built to be thread safe and will add information in a fixed format
 * so that it can be parsed in data analyses automatically. 
 *
 */
public class LIOMInfoFileHandler {
	Properties p_acq_props=null; 
	String p_header=null;
	String p_current_exp_dir=null;
	public LIOMInfoFileHandler()
	{
		/* Open file info.txt in directory, validate directory exists, create 
		 * header and specify version */
			p_acq_props = new Properties();
			p_acq_props.setProperty("Version","1.0");
			p_header="Empty Experiment Header";
	}	
	
	public void setCurrentDir( String current_exp_dir ){
		p_current_exp_dir = current_exp_dir;
	}
	
	public void addHeader( String hdr )
	{
		/* Open file info.txt in directory, validate directory exists, create 
		 * header and specify version */
		p_header=hdr;
	}	
	
	public void addDoubleInfo( String key, double data )
	{
		/* Add data to file, print string : data */
		
		p_acq_props.setProperty(key,String.format("%f", data) );
		
	}
	public void addIntInfo( String key, int data )
	{
		/* Add data to file, print string : data */
		p_acq_props.setProperty(key,String.format("%d", data) );

		
	}	
	public void addDoubleVecInfo( String key, double[] data ){
		/* Add data to file, print string : data */
		
	}	
	public void saveInfoFile(){
		String info_file = p_current_exp_dir + File.separator + "info.txt";
		try{
			OutputStream file = new FileOutputStream(new File(info_file));
			p_acq_props.store(file,p_header);
		}
		catch( Exception e){
			System.out.println(e);
		}

	}

}
